package leetcode_day._2022._202202._0110;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/2/2 22:16
 * 反转单词前缀
 * 算法：双指针
 */
public class _02_2000 {
    public static void main(String[] args) {
        System.out.println(new _02_2000().reversePrefix("abcd", 'z'));
    }

    public String reversePrefix(String word, char ch) {
        int idx = 0, len = word.length();
        char[] ans = word.toCharArray();
        for (; idx < len; idx++) if (ans[idx] == ch) break;
        int l = 0;
        while (idx < len && l < idx) {
            char tmp = word.charAt(l);
            ans[l++] = ans[idx];
            ans[idx--] = tmp;
        }
        return new String(ans);
    }

}
